<?php  
namespace Home\Controller;
use Think\Controller;
class SetController extends Controller {   
    public function index(){
    	$id = $_SESSION['id'];

    	$user = M('user')->where(array('id'=>$id))->find();

    	$this->assign('user',$user);

   		$this->display();

   }
   	public function checkdata(){

   		$id = $_SESSION['id'];
   		$nickname= $_POST['nickname'];
   		$email= $_POST['email'];
   		$sql="select * from user where id!=$id and email='{$email}'";
   		$res=M()->query($sql);  //原始的取出数据的方法
   		if ($res) {
   			$arr=array(
   				'error'=>1,
   				'info'=>'邮箱已经被占用',
   			);
   			echo json_encode($arr);
   			exit;
   		}
   		$sql="select * from user where id!=$id and nickname='{$nickname}'";
   		$res=M()->query($sql);  //原始的取出数据的方法
   		if($res){
   			$arr=array(
   				'error'=>1,
   				'info'=>'昵称已经被占用',
   				
   			);
   			echo json_encode($arr);
   			exit;
   		}
   		$data=I('post.');
   		$save=M('user')->where("id=$id")->save($data);//保存上面post过来(修改)的数据;
   		if ($save) {

   			$arr=array(
   				'error'=>0,
   				'info'=>'修改成功',
   				
   			);
   			echo json_encode($arr);
   			exit;
   		}else{
   			$arr=array(
   				'error'=>1,
   				'info'=>'修改失败',
   				
   			);
   			echo json_encode($arr);
   			exit;
   		}
   	}
      public function face(){
      $this->display();

      }
      public function upload(){
          $upload = new \Think\Upload();// 实例化上传类
          $upload->maxSize   =     3145728 ;// 设置附件上传大小
          $upload->exts      =     array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
          $upload->rootPath  =     './Uploads/'; // 设置附件上传根目录
          $upload->savePath  =     ''; // 设置附件上传（子）目录
          // 上传文件 
          $info   =   $upload->upload();  //上传的数据全部放在$info里面
          // var_dump($info);//打印一下看看
          if(!$info) {// 上传错误提示错误信息
              echo ($upload->getError());
          }else{// 上传成功
            $info = current($info);//取当前上传的文件
            $path = "Uploads/".$info['savepath'].$info['savename'];
            $res = M('user')->where(array('id'=>$_SESSION['id']))->save(array('face'=>$path));
            $_SESSION['face']=$path;//

          }
         
   }
         


}

 ?>  